//
//  EditPhoneViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/8/28.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "EditPhoneViewController.h"
#import "ChangePhoneViewController.h"
#import "RentVieitor.h"



@interface EditPhoneViewController ()

@end

@implementation EditPhoneViewController {
    
    UITextField *phoneField;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"绑定手机号";
    self.view.backgroundColor = BackgroundColor;
    [self creatLeftView];
    [self creatView];
}

- (void)creatLeftView {
    
    // 自定义导航栏左侧按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 80,15 );
    [leftBtn setImage:[UIImage imageNamed:@"箭头左"] forState:UIControlStateNormal];
    [leftBtn setTitle:@"取消" forState:UIControlStateNormal];
    leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [leftBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
    leftBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [leftBtn setTitleColor:[Utils colorConvertFromString:@"#333333"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    // 自定义导航栏左侧按钮
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    rightBtn.frame = CGRectMake(0, 0, 50, 20);
    [rightBtn setTitle:@"下一步" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor colorWithRed:225/255.0 green:141/255.0 blue:43/255.0 alpha:1] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    
}

- (void)creatView {
    
//    UILabel *proLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, KWidth, 50)];
//    if (self.phone == nil) {
//        proLabel.text = @"当前未绑定任何手机号,请绑定";
//    }else {
//        proLabel.text = @"当前已绑定手机号";
//    }
//    
//    proLabel.textColor = [Utils colorConvertFromString:@"#666666"];
//    proLabel.font = [UIFont systemFontOfSize:15];
//    proLabel.textAlignment = NSTextAlignmentCenter;
//    [self.view addSubview:proLabel];
    
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, KWidth, 100)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView];
    
    UILabel *phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, KWidth-70, 30)];
    phoneLabel.text = @"国家/地区      中国";
    phoneLabel.textColor = [Utils colorConvertFromString:@"#101010"];
    phoneLabel.font = [UIFont systemFontOfSize:15];
    phoneLabel.textAlignment = NSTextAlignmentLeft;
    [whiteView addSubview:phoneLabel];
    
    //分割线
    CALayer *MlineLayer = [CALayer layer];
    MlineLayer.backgroundColor = [[Utils colorConvertFromString:@"#cfcfcf"] CGColor];
    MlineLayer.frame = CGRectMake(20 ,49, KWidth-40, 1);
    [whiteView.layer addSublayer:MlineLayer];
    
    CGSize size = [@"国家/地区" boundingRectWithSize:CGSizeMake(KWidth, 35) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:phoneLabel.font} context:nil].size;
    //分割线
    CALayer *MlineLayer2 = [CALayer layer];
    MlineLayer2.backgroundColor = [[Utils colorConvertFromString:@"#cfcfcf"] CGColor];
    MlineLayer2.frame = CGRectMake(size.width+20,50,1, 50);
    [whiteView.layer addSublayer:MlineLayer2];
    
    UILabel *sectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, KWidth-70, 30)];
    sectionLabel.text = @"+86";
    sectionLabel.textColor = [Utils colorConvertFromString:@"#101010"];
    sectionLabel.font = [UIFont systemFontOfSize:15];
    sectionLabel.textAlignment = NSTextAlignmentLeft;
    [whiteView addSubview:sectionLabel];
    
    phoneField = [[UITextField alloc] initWithFrame:CGRectMake(size.width+20+25, 60, KWidth-(size.width+20+25), 30)];
    phoneField.placeholder = @"请填写手机号";

    phoneField.textColor = [Utils colorConvertFromString:@"#101010"];
    phoneField.font = [UIFont systemFontOfSize:13];
    [whiteView addSubview:phoneField];
    

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [self.view endEditing:YES];
}

- (void)backAction {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)nextAction {
    
    ChangePhoneViewController *phVc = [[ChangePhoneViewController alloc] init];
    phVc.phone = phoneField.text;
    phVc.auth = self.auth;
    [self.navigationController pushViewController:phVc animated:YES];
}
@end
